package cn.wolfcode.trip.base.service.impl;

import cn.wolfcode.trip.base.domain.SystemNotice;
import cn.wolfcode.trip.base.domain.TravelCommend;
import cn.wolfcode.trip.base.mapper.SystemNoticeMapper;
import cn.wolfcode.trip.base.mapper.TravelCommendMapper;
import cn.wolfcode.trip.base.query.TravelCommendQueryObject;
import cn.wolfcode.trip.base.service.ITravelCommendService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class travelCommendServiceImpl implements ITravelCommendService{
    @Autowired
    private TravelCommendMapper travelCommendMapper;
    @Autowired
    private SystemNoticeMapper noticeMapper;
    @Override
    public void saveOrUpdate(TravelCommend commend) {
        if (commend.getId() == null) {
            travelCommendMapper.insert(commend);
            /*SystemNotice systemNotice=new SystemNotice();
            systemNotice.setTravel(commend.getTravel());
            systemNotice.setUser(commend.getTravel().getAuthor());
            systemNotice.setMessage(commend.getTypeName());
            noticeMapper.insert(systemNotice);*/
        }else{
            travelCommendMapper.updateByPrimaryKey(commend);
        }


    }

    @Override
    public PageInfo query(TravelCommendQueryObject qo) {
        PageHelper.startPage(qo.getCurrentPage(),qo.getPageSize(),qo.getOrderBy());
        List<TravelCommend> list = travelCommendMapper.selectForList(qo);
        return new PageInfo(list);
    }

    @Override
    public PageInfo selectForAppList(TravelCommendQueryObject qo) {
        PageHelper.startPage(qo.getCurrentPage(),qo.getPageSize(),qo.getOrderBy());
        List<Map> list = travelCommendMapper.selectForAppList(qo);
        return new PageInfo(list);
    }
}
